<template>
	<view>
		<u-navbar back-icon-size='48' title="通讯录" :is-back='false'>
			<view slot='right' style="padding-right: 32rpx;color: #3587F7;font-size: 32rpx;" @click="cancel">
				取消
			</view>
		</u-navbar>
		<view class="searchBox">
			<u-search placeholder="查找联系人" v-model="keyword" :show-action='false'></u-search>
		</view>
		<view class="content">
			<view class="content-li" v-for="(item,index) in bookList" :key='index'>
				<view class="name">
					<!-- {{item.displayName}} -->
				</view>
				<view class="mobile">
					<!-- {{item.phoneNumbers[0].value}} -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import myRequest from '@/api/index.js'
	export default {
		data() {
			return {
				keyword: '',
				bookList: [],
			}
		},
		onLoad() {
			this.getBooks()
		},
		methods: {
			// 获取通讯录对象
			getBooks() {
				var that = this
				// #ifdef APP-PLUS
				plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, function(addressbook) {
					addressbook.find(["displayName", "phoneNumbers"], function(contacts) {
						console.log(contacts)
					}, function() {
						this.addressBook()
					}, {
						multiple: true
					});
				}, function(e) {
					this.addressBook()
				});
				// #endif
			},
			// 获取通讯录权限
			addressBook() {
				var platform = uni.getSystemInfoSync().platform
				uni.showModal({
					title: '提示',
					content: 'APP通讯录权限没有开启，是否开启？',
					success(res) {
						if (res.confirm) {
							if (platform == 'ios') {
								var UIApplication = plus.ios.import("UIApplication");
								var NSURL2 = plus.ios.import("NSURL");
								var setting2 = NSURL2.URLWithString("app-settings:");
								var application2 = UIApplication.sharedApplication();
								application2.openURL(setting2);
								plus.ios.deleteObject(setting2);
								plus.ios.deleteObject(NSURL2);
								plus.ios.deleteObject(application2);
							} else {
								var main = plus.android.runtimeMainActivity();
								var bulid = plus.android.importClass("android.os.Build");
								var Intent = plus.android.importClass('android.content.Intent');
								if (bulid.VERSION.SDK_INT >= 9) {
									var intent = new Intent('android.settings.APPLICATION_DETAILS_SETTINGS');
									var Uri = plus.android.importClass('android.net.Uri');
									var uri = Uri.fromParts("package", main.getPackageName(), null)
									intent.setData(uri);
									intent.putExtra('android.content.Intent.setFlags', Intent
										.FLAG_ACTIVITY_NEW_TASK);
								} else if (bulid.VERSION.SDK_INT <= 8) {
									var intent = new Intent(Intent.ACTION_VIEW);
									intent.setClassName("com.android.settings",
										"com.android.settings.InstalledAppDetails");
									intent.putExtra("com.android.settings.ApplicationPkgName", main
										.getPackageName());
									intent.putExtra('android.content.Intent.setFlags', Intent
										.FLAG_ACTIVITY_NEW_TASK);
								}
								main.startActivity(intent);
							}
						}
					}
				})
			},
			cancel() {
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.searchBox {
		width: 100%;
		height: 120rpx;
		background: #FFFFFF;
		padding: 26rpx 28rpx;

		input {
			width: 694rpx;
			height: 68rpx;
			background: #F2F2F7;
			border-radius: 36rpx;
		}
	}

	.content {
		width: 100%;
		height: auto;
		background-color: #FFFFFF;
		padding: 0 28rpx;

		.content-li {
			&:last-child {
				border-bottom: none
			}

			line-height: 88rpx;
			width: 100%;
			height: 88rpx;
			border-bottom: 2rpx solid #F2F2F7;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
	}
</style>
